home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Table / Sources / Selection.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  12.9 KB  |  430 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Selection.cpp
  4. //    Release Version:    $ ODF 3 $ 
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. // ----- TablePart Includes -----
  13.  
  14. #ifndef SELECTION_H
  15. #include "Selection.h"
  16. #endif
  17.  
  18. #ifndef PROXY_H
  19. #include "Proxy.h"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef LINKING_H
  27. #include "Linking.h"
  28. #endif
  29.  
  30. #ifndef CONTENT_H
  31. #include "Content.h"
  32. #endif
  33.  
  34. #ifndef VIEW_H
  35. #include "View.h"
  36. #endif
  37.  
  38. // ----- ODF Includes -----
  39.  
  40. #ifndef FWFRAME_H
  41. #include "FWFrame.h"
  42. #endif
  43.  
  44. #ifndef FWRECT_H
  45. #include "FWRect.h"
  46. #endif
  47.  
  48. #ifndef FWUTIL_H
  49. #include "FWUtil.h"
  50. #endif
  51.  
  52. #ifndef FWPRESEN_H
  53. #include "FWPresen.h"
  54. #endif
  55.  
  56. #ifndef FWITERS_H
  57. #include "FWIters.h"
  58. #endif
  59.  
  60. #ifndef FWCONTXT_H
  61. #include "FWContxt.h"
  62. #endif
  63.  
  64. // ----- OS Layer -----
  65.  
  66. #ifndef FWODGEOM_H
  67. #include "FWODGeom.h"
  68. #endif
  69.  
  70. #ifndef FWEVENT_H
  71. #include "FWEvent.h"
  72. #endif
  73.  
  74. // ----- OpenDoc Includes -----
  75.  
  76. #ifndef SOM_ODShape_xh
  77. #include <Shape.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODTransform_xh
  81. #include <Trnsform.xh>
  82. #endif
  83.  
  84. #ifndef SOM_ODSession_xh
  85. #include <ODSessn.xh>
  86. #endif
  87.  
  88. //========================================================================================
  89. // RunTime Info
  90. //========================================================================================
  91.  
  92. #ifdef FW_BUILD_MAC
  93. #pragma segment odfTable
  94. #endif
  95.  
  96. FW_DEFINE_AUTO(CTableSelection)
  97.  
  98. //========================================================================================
  99. //    class CTableSelection
  100. //========================================================================================
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    CTableSelection::CTableSelection
  104. //----------------------------------------------------------------------------------------
  105.  
  106. CTableSelection::CTableSelection(Environment* ev, CTablePart* tablePart, CTablePartContent* content) :
  107.     FW_CSelection(ev, true, true),    // allow linking
  108.     fTablePart(tablePart),
  109.     fTableContent(content)
  110. {
  111.     fSelectionContent = FW_NEW(CTableSelectionContent, (ev, tablePart, content));
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    CTableSelection::~CTableSelection
  116. //----------------------------------------------------------------------------------------
  117.  
  118. CTableSelection::~CTableSelection()
  119. {
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    CTableSelection::GetSelectedContent
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_CContent* CTableSelection::GetSelectedContent(Environment* ev)
  127. {
  128. FW_UNUSED(ev);
  129.     return fSelectionContent;
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. //    CTableSelection::IsEmpty
  134. //----------------------------------------------------------------------------------------
  135.  
  136. FW_Boolean CTableSelection::IsEmpty(Environment* ev) const
  137. {
  138.     return fSelectionContent->GetSelectedProxy(ev) == NULL;
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. //    CTableSelection::CloseSelection
  143. //----------------------------------------------------------------------------------------
  144.  
  145. void CTableSelection::CloseSelection(Environment* ev)
  146. {
  147. FW_UNUSED(ev);
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    CTableSelection::ClearSelection
  152. //----------------------------------------------------------------------------------------
  153.  
  154. void CTableSelection::ClearSelection(Environment* ev)
  155. {
  156.     FW_CLinkManager* linkMgr = this->GetPart(ev)->GetLinkManager(ev);
  157.     CTableLinkSource* pendingSrc = 
  158.         (CTableLinkSource*)linkMgr->GetPendingClipboardLink(ev);
  159.         
  160.     if (pendingSrc != NULL && pendingSrc->GetCell(ev) == this->GetSelectedCell())
  161.     {
  162.         linkMgr->DeletePendingClipboardLink(ev);
  163.     }
  164.         
  165.     CTableProxy* proxy = fSelectionContent->GetSelectedProxy(ev);
  166.     if (proxy)
  167.     {
  168.         //--- Remove the proxy ---
  169.         proxy->DetachEmbeddedFrames(ev);
  170.         fTableContent->RemoveProxy(proxy);
  171.         InvalidateSelection(ev);
  172.     }
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    CTableSelection::SelectAll
  177. //----------------------------------------------------------------------------------------
  178.  
  179. void CTableSelection::SelectAll(Environment* ev)
  180. {
  181. FW_UNUSED(ev);
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. //    CTableSelection::Select
  186. //----------------------------------------------------------------------------------------
  187.  
  188. void CTableSelection::Select(Environment* ev, const CCell& cell)
  189. {
  190.     // Get the active frame
  191.     CTableFrame* activeFrame = (CTableFrame*)fTablePart->GetLastActiveFrame(ev);
  192.  
  193.     // Get the previous selected cell and proxy
  194.     CCell oldCell = fSelectionContent->GetCell();
  195.     CTableProxy* proxy = fTableContent->CellToProxy(oldCell);
  196.  
  197.     // Get the link manager so we can check for links
  198.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  199.     CTableLink* link = NULL;
  200.     CTableLinkSource* linkSource = NULL;
  201.  
  202.     // if the previous selected cell was containing a proxy then change its selected state
  203.     // and change its hilite
  204.     if (proxy)
  205.     {
  206.         proxy->SetSelectState(ev, FALSE);
  207.  
  208.         link = linkMgr->CellToLink(ev, oldCell);
  209.         if (link)
  210.             link->Select(ev, false);
  211.         linkSource = linkMgr->CellToSourceLink(ev, oldCell);
  212.         if (linkSource)
  213.             linkSource->Select(ev, false);
  214.     }
  215.     
  216.     // Erase the cell hilite
  217.     if (activeFrame)
  218.         activeFrame->GetTableView(ev)->ChangeHighlightState(ev, kODNoHighlight);
  219.  
  220.     // select the new cell
  221.     fSelectionContent->SetCell(cell);
  222.     
  223.     // get the proxy contained in the new selected cell
  224.     proxy = fTableContent->CellToProxy(cell);
  225.     
  226.     // if the new selected cell contains a proxy then change its selected state
  227.     // and hilite
  228.     if (proxy)
  229.     {
  230.         proxy->SetSelectState(ev, TRUE);
  231.  
  232.         link = linkMgr->CellToLink(ev, cell);
  233.         if (link)
  234.             link->Select(ev, true);
  235.         linkSource = linkMgr->CellToSourceLink(ev, cell);
  236.         if (linkSource)
  237.             linkSource->Select(ev, true);
  238.     }
  239.  
  240.     // Draw the cell hilite
  241.     if (activeFrame)
  242.         activeFrame->GetTableView(ev)->ChangeHighlightState(ev, activeFrame->HasSelectionFocus(ev) ? kODFullHighlight : kODDimHighlight);    
  243. }
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    CTableSelection::AcquireSelectionShape
  247. //----------------------------------------------------------------------------------------
  248.  
  249. ODShape* CTableSelection::AcquireSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  250. {
  251.     FW_UNUSED(facet);
  252.     FW_UNUSED(frame);
  253.  
  254.     return fSelectionContent->AcquireSuggestedFrameShape(ev);
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    CTableSelection::InvalidateSelection
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void CTableSelection::InvalidateSelection(Environment* ev)
  262. {
  263.     FW_CAcquiredODShape aqShape = fSelectionContent->AcquireSuggestedFrameShape(ev);
  264.     GetPresentation(ev)->Invalidate(ev, aqShape);
  265. }
  266.  
  267. //----------------------------------------------------------------------------------------
  268. // CTableSelection::SelectProxy
  269. //----------------------------------------------------------------------------------------
  270.  
  271. void CTableSelection::SelectProxy(Environment* ev, CTableProxy* proxy)
  272. {
  273.     CCell cell = proxy->GetCell();
  274.     this->Select(ev, cell);
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. // CTableSelection::GetSelectedCell
  279. //----------------------------------------------------------------------------------------
  280.  
  281. CCell CTableSelection::GetSelectedCell() const
  282. {
  283.     return fSelectionContent->GetCell();
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. // CTableSelection::GetSelectedProxy
  288. //----------------------------------------------------------------------------------------
  289.  
  290. CTableProxy* CTableSelection::GetSelectedProxy() const
  291. {
  292.     CCell selectedCell = fSelectionContent->GetCell();
  293.     return fTableContent->CellToProxy(selectedCell);
  294. }
  295.  
  296. //----------------------------------------------------------------------------------------
  297. //    CTableSelection::IsMouseInDraggableItem
  298. //----------------------------------------------------------------------------------------
  299.  
  300. FW_Boolean CTableSelection::IsMouseInDraggableItem(Environment* ev, 
  301.                                                 FW_CFrame* frame, 
  302.                                                 const FW_CMouseEvent& theMouseEvent, 
  303.                                                 FW_Boolean inBackground)
  304. {
  305.     FW_UNUSED(inBackground);
  306.  
  307.     CCell cell;
  308.     ETableLoc tl = fTableContent->HitTest(ev, theMouseEvent, frame->GetContentView(ev), cell);
  309.     
  310.     return (tl == kTLCell && fTableContent->CellToProxy(cell) != NULL);
  311. }
  312.  
  313. //----------------------------------------------------------------------------------------
  314. // CTableSelection::UpdateSelectionOnMouseDown
  315. //----------------------------------------------------------------------------------------
  316.  
  317. void CTableSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  318.                                             const FW_CMouseEvent& mouseEvent,
  319.                                             ODFacet* embeddedFacet,
  320.                                             FW_Boolean inEmbeddedFrameBorder,
  321.                                             FW_Boolean inBackground)
  322. {
  323.     FW_UNUSED(inBackground);
  324.  
  325.     CTableFrame* tableFrame = (CTableFrame*)FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
  326.     
  327.     if (tableFrame->GetTableView(ev)->IsGridShown(ev))
  328.     {
  329.         FW_Boolean select = FALSE;
  330.         CCell cell;
  331.         
  332.         if (inEmbeddedFrameBorder)
  333.         {
  334.             FW_MProxy* proxy = tableFrame->GetProxy(ev, embeddedFacet->GetFrame(ev));
  335.             FW_ASSERT(proxy);
  336.             
  337.             cell = ((CTableProxy*)proxy)->GetCell();    
  338.             select = TRUE;
  339.         }
  340.         else
  341.         {
  342.             ETableLoc tl = fTableContent->HitTest(ev, mouseEvent, tableFrame->GetContentView(ev), cell);    
  343.             select = (tl == kTLCell && cell != GetSelectedCell());
  344.         }
  345.         
  346.         if (select)
  347.             Select(ev, cell);
  348.     }
  349. }
  350.  
  351. //----------------------------------------------------------------------------------------
  352. //    CTableSelection::CanPasteAsLink
  353. //---------------------------------------------------------------------------------------
  354.  
  355. FW_Boolean CTableSelection::CanPasteAsLink(Environment* ev, ODPasteAsMergeSetting& setting,
  356.                                             ODStorageUnit* su)
  357. {
  358. #ifndef FW_DEBUG
  359. FW_UNUSED(ev);
  360. #endif
  361. FW_UNUSED(su);
  362.     setting = kODPasteAsEmbedOnly;    // table has no content to merge
  363.  
  364.     // we shouldn't be here at all unless the selection is empty
  365.     
  366.     FW_ASSERT(this->IsEmpty(ev));
  367.     return TRUE;
  368. }
  369.  
  370. //----------------------------------------------------------------------------------------
  371. //    CTableSelection::IsSelectionLinkable
  372. //----------------------------------------------------------------------------------------
  373.  
  374. FW_Boolean CTableSelection::IsSelectionLinkable(Environment* ev)
  375. {
  376.     FW_Boolean result = fAllowLinkSource;
  377.  
  378.     if (fAllowLinkSource)
  379.     {
  380.         // make sure the cell is not a link destination
  381.         CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  382.         if (linkMgr->CellToLink(ev, this->GetSelectedCell()))
  383.             result = FALSE;
  384.     }
  385.  
  386.     return result;
  387. }
  388.  
  389. //----------------------------------------------------------------------------------------
  390. //    CTableSelection::DoFindLinkSource
  391. //----------------------------------------------------------------------------------------
  392.  
  393. FW_CLinkSource* CTableSelection::DoFindLinkSource(Environment* ev)    // Override
  394. {
  395.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  396.     return linkMgr->CellToSourceLink(ev, fSelectionContent->GetCell());
  397. }
  398.  
  399. //----------------------------------------------------------------------------------------
  400. //    CTableSelection::GetLinkDestination
  401. //----------------------------------------------------------------------------------------
  402.  
  403. FW_CLinkDestination* CTableSelection::GetLinkDestination(Environment* ev, FW_Boolean& multipleLinks)
  404. {
  405. FW_UNUSED(multipleLinks);
  406.     // check whether the selected part is in a link destination
  407.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  408.     return linkMgr->CellToLink(ev, this->GetSelectedCell());
  409. }
  410.  
  411. //----------------------------------------------------------------------------------------
  412. //    CTableSelection::GetSavedLinkSpecID
  413. //----------------------------------------------------------------------------------------
  414. ODUpdateID CTableSelection::GetSavedLinkSpecID(Environment* ev)
  415. {
  416.     // Return the link spec ID saved in the currently selected proxy
  417.     CTableProxy* selectedProxy = fSelectionContent->GetSelectedProxy(ev);
  418.     return selectedProxy->GetLinkSpecID();
  419. }
  420.  
  421. //----------------------------------------------------------------------------------------
  422. //    CTableSelection::SaveLinkSpecID
  423. //----------------------------------------------------------------------------------------
  424. void CTableSelection::SaveLinkSpecID(Environment* ev, ODUpdateID linkSpecID)
  425. {
  426.     // Save the link spec ID in the currently selected proxy
  427.     CTableProxy* selectedProxy = fSelectionContent->GetSelectedProxy(ev);
  428.     selectedProxy->SetLinkSpecID(linkSpecID);
  429. }
  430.